package com.zhuoyue.web.controller.v2;


import com.zhuoyue.biz.core.api.domain.RoomDO;
import com.zhuoyue.biz.core.api.dto.rep.RoomRepDTO;
import com.zhuoyue.biz.core.api.dto.req.RoomReqDTO;
import com.zhuoyue.biz.core.api.service.impl.RoomService;
import com.zhuoyue.common.aop.auth.CheckLogin;
import com.zhuoyue.common.aop.version.ApiVersion;
import com.zhuoyue.common.dto.BaseResultDTO;
import com.zhuoyue.common.dto.ControllerResult;
import com.zhuoyue.common.exception.ErrorType;
import com.zhuoyue.common.exception.ZyServerException;
import com.zhuoyue.common.group.ValidationGroups;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;


/**
 * @author wjming
 */
@RestController
@Scope("prototype")
@Validated
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AppRoomV2Controller {

    private final RoomService roomService;


    /**
     * 添加房间信息
     *
     * @return
     */
//    @PostMapping("/api/room/add")
//    @CheckLogin
//    @ApiVersion(value = "1.4.0")
    public ControllerResult addRoom(@Validated({ValidationGroups.Insert.class}) RoomReqDTO roomReqDTO) {
        RoomDO room = new RoomDO().roomReqDtoToRoomDo(roomReqDTO);
        return ControllerResult.toReturnDataSuccess("添加成功", roomService.saveAndReturnRepDto(room));
    }


    /**
     * 修改房间信息
     *
     * @return
     */
//    @PutMapping("/api/room/modify")
//    @CheckLogin
//    @ApiVersion(value = "1.4.0")
    public ControllerResult updateRoomById(@Validated({ValidationGroups.Update.class}) RoomReqDTO roomReqDTO) {
        RoomDO room = new RoomDO().roomReqDtoToRoomDo(roomReqDTO);
        roomService.updateRoomById(room);
        return ControllerResult.toReturnMessageSuccess("修改成功");
    }
}
